package com.eagle.parser;

import java.util.List;

public class ParserUtil {

    //基本类型
    private static String[] basicTypes={"string","int","boolean","double","float","short","byte","long","char","integer"};



    //判断是否为基本类型参数
    public static boolean checkParameterType(ParameterInfo parameterInfo){
        boolean flag=false;
        for(String basicType:basicTypes){
            if(parameterInfo.getType().equalsIgnoreCase(basicType) || parameterInfo.getType().equalsIgnoreCase(basicType+"[]")){
                flag=true;
                break;
            }
        }
        return flag;
    }

    //判断是否为基本类型参数
    public static boolean isBasicType( String returnType){
        boolean flag=false;
        for(String basicType:basicTypes){
            if(returnType.equalsIgnoreCase(basicType) || returnType.equalsIgnoreCase(basicType+"[]")){
                flag=true;
                break;
            }
        }
        return flag;
    }

    //创建导包内容
    public static ImportInfo createImportInfo(String importStr){
        ImportInfo importInfo=new ImportInfo();
        importInfo.setImportPath(importStr);
        importInfo.setVoName(importStr.substring(importStr.lastIndexOf("/")));
        return importInfo;
    }

    /**
     * 获取vo 路径
     * @param entityPath  当前java所在svn路径
     * @param packagePath 包路径
     * @param voName      vo类名
     * @param importInfoList 导包路径
     * @return
     */
    public static String makeVoPath(String entityPath, String packagePath,String voName, List<ImportInfo> importInfoList){
        String targetImport="";
        if(importInfoList!=null && importInfoList.size()>0){
            for(ImportInfo importInfo:importInfoList){
                if(importInfo.getVoName().endsWith(voName)){
                    targetImport=makeVoPath(entityPath,packagePath,importInfo.getImportPath());
                }
            }
        }
        return targetImport;
    }

    public static String makeVoPath(String entityPath,String packagePath,String importPath){
        System.out.println(entityPath);
        //System.out.println(packagePath.replaceAll("\\.","/"));
        String basicPath=entityPath.substring(0,entityPath.lastIndexOf(packagePath.replaceAll("\\.","/")));
        return basicPath+importPath.replaceAll("\\.","/")+".java";
    }

    public static void main(String[] args) {
        System.out.println(makeVoPath("/zt/etax-fpyzdb-app/trunk/etax-fpyzdb-app/etax-fpyzdb-service/src/main/java/com/css/etax/fpyzdb/service/micro/FpyzdbCshszMicroService.java",
                "com.css.etax.fpyzdb.service.micro","com.css.etax.fpyzdb.vo.kfkc.FPBcczrykfdbxxVO"));
    }

}
